/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Master_LihatJadwal.java
 *
 * Created on Nov 19, 2012, 4:22:22 PM
 */
package rploo_ciayoo;

import Penjadwalan.JadwalKontrol;
import Penjadwalan.Penjadwalan;
import Penjadwalan.PenjadwalanTabelModel;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import rploo_ciayoo.kontrol.KoneksiDatabase;

/**
 *
 * @author Yulius
 */
public class Master_LihatJadwal extends javax.swing.JInternalFrame {

    /**
     * Creates new form Master_LihatJadwal
     */
    public Master_LihatJadwal() {
        initComponents();
        lihatSemua();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        tabelJadwal = new javax.swing.JTable();
        KeluarLihatJadwal = new javax.swing.JButton();
        hariCmbx = new javax.swing.JComboBox();
        cariBtn = new javax.swing.JButton();

        jLabel1.setText("Hari :");

        tabelJadwal.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Hari", "Jam", "Kelas", "Id Matakuliah", "Id Dosen", "Id Ruang"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                true, true, true, true, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane5.setViewportView(tabelJadwal);

        KeluarLihatJadwal.setText("Keluar");
        KeluarLihatJadwal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                KeluarLihatJadwalActionPerformed(evt);
            }
        });

        hariCmbx.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Senin", "Selasa", "Rabu", "Kamis", "Jumat" }));

        cariBtn.setText("cari");
        cariBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cariBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(hariCmbx, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(cariBtn)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(605, Short.MAX_VALUE)
                .addComponent(KeluarLihatJadwal)
                .addGap(141, 141, 141))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 789, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(hariCmbx, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cariBtn))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 285, Short.MAX_VALUE)
                .addComponent(KeluarLihatJadwal)
                .addGap(30, 30, 30))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(70, 70, 70)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(82, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void KeluarLihatJadwalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_KeluarLihatJadwalActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_KeluarLihatJadwalActionPerformed

    private void cariBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cariBtnActionPerformed
        // TODO add your handling code here:
        try {
            JadwalKontrol dbKon;
            List<Penjadwalan> dbList = null;
            String nama = (String) hariCmbx.getSelectedItem();
            System.out.println(nama);
            dbKon = JadwalKontrol.getKoneksi();
            dbList = dbKon.getNamaHari(nama);
            PenjadwalanTabelModel dbTabel = new PenjadwalanTabelModel(dbList);
            tabelJadwal.setModel(dbTabel);
        } catch (SQLException ex) {
            Logger.getLogger(Master_LihatJadwal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_cariBtnActionPerformed

    public void lihatSemua() {
        try {
            List<Penjadwalan> dos = JadwalKontrol.getKoneksi().lihatSeluruhJadwal();
            PenjadwalanTabelModel table = new PenjadwalanTabelModel(dos);
            tabelJadwal.setModel(table);
        } catch (SQLException ex) {
            Logger.getLogger(Master_LihatJadwal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton KeluarLihatJadwal;
    private javax.swing.JButton cariBtn;
    private javax.swing.JComboBox hariCmbx;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTable tabelJadwal;
    // End of variables declaration//GEN-END:variables
}
